//package com.fingard.dsp.bank.directbank.boc02;
//
//import java.util.Date;
//
//import com.fingard.constant.Format;
//import com.fingard.dsp.bank.directbank.DirectBase;
//import com.fingard.dsp.bank.directbank.boc02.utils.RSAHelper;
//import com.fingard.io.FileHelper;
//import com.fingard.net.ITcpClient;
//import com.fingard.net.TcpReceiver;
//import com.fingard.net.WebRequest;
//import com.fingard.text.StringHelper;
//import com.fingard.xml.XmlTextWriter;
//
//
//public class BOC02Base extends DirectBase implements ITcpClient {
//
//    @Override
//    public void getContentLength(TcpReceiver p_receiver) throws Exception {
//        System.out.println("p_receiver.connState" + p_receiver.connState);
//        if (p_receiver.contentLength == -1) {
//            String tmpCharset = getCharset();
//            String tmpRecNow = new String(p_receiver.recBytes, 0, p_receiver.readedLength, tmpCharset);
//            if (tmpRecNow.contains("</transaction>")) {
//                p_receiver.contentLength = p_receiver.readedLength;
//                p_receiver.contentStartIndex = 0;
//            }
//        }
//    }
//
//
//    protected String getQryTransID() {
//        Date tmpDateNow = new Date();
//        return Format.Time12Format.format(tmpDateNow);
//    }
//
//    protected String getCharset() {
//        return getBankConfig().getCharset("UTF-8");
//    }
//
//    protected void writeCommonHeader(XmlTextWriter xmlWriter, BOC02Header p_bankHeader) throws Exception {
//        if (StringHelper.isNullOrEmpty(p_bankHeader.trncod)) {
//            throw new Exception("未赋值trncod");
//        }
//        if (StringHelper.isNullOrEmpty(p_bankHeader.trnid)) {
//            throw new Exception("未赋值trnid");
//        }
//        xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"" + getCharset() + "\"?>");
//        xmlWriter.writeStartElement("transaction");
//        xmlWriter.writeStartElement("header");
//        xmlWriter.writeElementString("ver", "1.0");
//        xmlWriter.writeStartElement("msg");
//        xmlWriter.writeElementString("msgCd", p_bankHeader.trncod);
//        xmlWriter.writeElementString("callTyp", "SYN");
//        xmlWriter.writeElementString("seqNb", p_bankHeader.trnid);
//        xmlWriter.writeElementString("sndAppCd", bankFront.org);
//        xmlWriter.writeElementString("sndDt", Format.Date8Format.format(new Date()));
//        xmlWriter.writeElementString("sndTm", Format.Time9Format.format(new Date()));
//        xmlWriter.writeEndElement();
//        xmlWriter.writeElementString("signature", "");
//        xmlWriter.writeEndElement();
//        xmlWriter.writeStartElement("body");
//    }
//
//    protected String[] sendToBank(String p_reqStr) throws Exception {
//        String[] retStr = new String[]{"", ""};
//
//        WriteBankLogLn("2.提交银行的地址：" + bankFront.serverURL);
//        WriteBankLogStep2(p_reqStr);
//
//        WebRequest tmpWebRequest = new WebRequest(bankFront.serverURL);
//        tmpWebRequest.setConnectTimeout(60000);
//        String charsetName = getCharset();
//        tmpWebRequest.setRequestProperty("Content-Type", "text/xml; charset=" + charsetName);
//        tmpWebRequest.setRequestProperty("connection", "Close");
//        byte[] tmpToWriteBytes = p_reqStr.getBytes(charsetName);
//        retStr = tmpWebRequest.upload(tmpToWriteBytes, charsetName);
//        WriteBankLogStep3(retStr[1]);
//
//        return retStr;
//    }
//
//    protected boolean isActiveRetCode(String retCode) {
//        if (retCode != null) {
//            if ("000000".equals(retCode)) {
//                bankFront.lastVisitTime = new Date();
//                return true;
//            }
//        }
//        return false;
//    }
//
//    public String signData(String raw) throws Exception {
//        String filePath = getBankConfig().getValueAsString("prikeyfile");
//        if (FileHelper.existFile(filePath)) {
//            String priKey = FileHelper.readFileText(filePath, getCharset());
//            String signdata = "";
//            //java的Signature API 的私钥签名
//            if (!"".equals(priKey) && priKey != null) {
//                signdata = RSAHelper.sign(raw, priKey.replace("\r", ""), getCharset());
//            }
//            return signdata;
//        } else {
//            throw new Exception("签名加密私钥文件不存在！");
//        }
//    }
//
//    public String getContentBetweenTag(String sbXml, String p_TagName) {
//        int Start = sbXml.indexOf("<" + p_TagName + ">");
//        int End = sbXml.lastIndexOf("</" + p_TagName + ">") + p_TagName.length() + 3;
//        if (End < Start || End > sbXml.length()) {
//            return "";
//        }
//        String str = sbXml.substring(Start, End);
//        return str;
//    }
//
//}
